package com.yeswater.rabbitmq;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yeswater.rabbitmq.utils.RabbitmqUtil;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * 死信队列实战 消费者
 * Author : yeswater
 */

public class Customer02 {

    // 死信队列
    public static final String DEAD_QUEUE = "dead_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitmqUtil.getChannel();

        // 声明死信队列
        // channel.queueDeclare(DEAD_QUEUE, false, false, false, null);

        System.out.println("等到接收消息...");

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
            System.out.println("consumer02 接收消息: " + new String(message.getBody(), StandardCharsets.UTF_8));
        };

        channel.basicConsume(DEAD_QUEUE, false, deliverCallback, (consumerTag) -> {
        });
    }


}
